package Logic;

import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;

import javax.swing.JOptionPane;
import Messages.*;
import ocsf.server.ConnectionToClient;
/**
 * this class runing the main tra
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
public class TaskAssignment {

 ConnectionToClient client;
 
	public TaskAssignment(Object msg, ConnectionToClient client) throws SQLException, IOException{
		
		
	
		  String[] str;
		  
		//  System.out.println(msg);

		  msg= msg.toString().substring(1, msg.toString().length()-1); // remove the [] from the msg by substring 
		  str = msg.toString().split("[ , ] "); // remove the , from msg and spliting it to tiny str array parts  
		
	//	  System.out.println(str[0]);
	//	  System.out.println(str[1]);             // test prints 
	//	  System.out.println(str[2]);
		  
		 
		  
	      switch(str[0])
	      {          
			      case ("Login"):
				  {
					
			    	  MessageLogin login =  new MessageLogin(str, client);  
			    	  login.Autorization();
					  
			      break;
				  }
			      
	      case ("AddUser"):
	      {
	    		
	    	  MessageAddUser AddUser =  new MessageAddUser(str, client);  
	    	  AddUser.AddUser();
	    	  break;
	      }
	      case ("Logout"):
	      {
	    		
	    	  MessageLogout ml =  new MessageLogout(str, client);  
	    	  ml.Logout(str[1],str[2]);
	    	  break;
	      }
	      case ("LendingCard"):
	      {
	    		
	    	  MessageLendingCard lc =  new MessageLendingCard(client);  
	    	  lc.SearchResult(str);
	    	  break;
	      }
	      case ("GiveBook"):
	      {
	    		
	    	  MessageGiveBook lc =  new MessageGiveBook(client,str[1]);  
	    	 
	    	  break;
	      }
	      case ("LatesReport"):
	      {
	    		
	    	  MessageLatesReport lc =  new MessageLatesReport(client);  
	    	  lc.Report(str);
	    	  break;
	      }
	      case ("LatesReportByBook"):
	      {
	    		
	    	  MessageLatesReportByBook lc =  new MessageLatesReportByBook(client);  
	    	  lc.Report(str);
	    	  break;
	      }
	      case ("ViewSubscriberDetails"): 
	      {
	    	  MessageViewSubscriberDetails mvsd = new MessageViewSubscriberDetails(client);
	    	  mvsd.viewdetail(str[1]);
	    	  break;
	    	  
	      }
	      
	      case ("EditDetails"): 
	      {
	    	  MessageEditDetails ed = new MessageEditDetails(client);
	    	  ed.viewdetail(str[1]);
	   
	    	  break;
	    	  
	      }
	      
	      case ("NewEmail"): 
	      {
	    	  MessageNewEmail ne = new MessageNewEmail();
	    	  client.sendToClient(ne.editmail(str));
	   
	    	  break;
	    	  
	      }
	      case ("GetLatesBooks"): 
	      {
	    	  GetLatesBooks gb = new GetLatesBooks(client);
	    	  gb.Report(str);
	   
	    	  break;
	    	  
	      }
	      
	      
	      case ("NewTelephone"): 
	      {
	    	  MessageNewTelephone nt = new MessageNewTelephone();
	    	  client.sendToClient(nt.edittelephone(str));
	   
	    	  break;
	    	  
	      }
	      case ("RemoveBook"): 
	      {
	    	  MessageRemovebook rb=new MessageRemovebook(client);
	    	  rb.viewbook(str);
	   
	    	  break;
	    	  
	      }
	      case ("GetCategory"): 
	      {
	    	  MessageGetCategory gc=new MessageGetCategory(client);
	    	  gc.getCat();
	   
	    	  break;
	    	  
	      }
	      case ("AddBook"): 
	      {
	    		MessageAddBookDB abdb = new MessageAddBookDB(client);
	    		abdb.AddBooktoDB(str);
	    		
	    	  break;
	    	  
	      }
	      case ("UpdateSearch"): 
	      {
	    	  MessageUpdateBookDetails ubd = new MessageUpdateBookDetails(client);
	    		ubd.UpdateBookDetails(str[1]);
	    		
	    	  break;
	    	  
	      }

	      case ("NewTitle"): 
	      {
	        	  MessageNewTitle nt = new MessageNewTitle(client);  
	    		nt.NewTitle(str);
	    		
	    	  break;
	    	  
	      }
	      case ("editAutor"): 
	      {
	        	  MessageEditAutor ea = new MessageEditAutor(client);  
	        	  ea.editAutor(str);
	    		
	    	  break;
	    	  
	      }
	      case ("EditDescription"): 
	      {
	        	  MessageEditDescription ed = new MessageEditDescription(client);  
	        	  ed.EditDescription(str);
	    		
	    	  break;
	    	  
	      }
	      case ("EditBuingDate"): 
	      {
	        	  MessageEditBuingDate ebd = new MessageEditBuingDate(client);  
	        	  ebd.EditBuingDate(str);
	    		
	    	  break;
	    	  
	      }
	      case ("EditCatalogNum"): 
	      {
	        	  MessageEditCatalogNum ecn = new MessageEditCatalogNum(client);  
	        	  ecn.EditCatalogNum(str);
	    		
	    	  break;
	    	  
	      }
	      case ("EditPrintDate"): 
	      {
	        	  MessageEditPrintDate epd = new MessageEditPrintDate(client);  
	        	  epd.EditPrintDate(str);
	    		
	    	  break;
	    	  
	      }
	      case ("EditionNum"): 
	      {
	        	  MessageEditEditionNum een = new MessageEditEditionNum(client);  
	        	  een.EditEditionNum(str);
	    		
	    	  break;
	    	  
	      }
	      case ("EditWanted"): 
	      {
	        	  MessageEditWanted ew = new MessageEditWanted(client);  
	        	  ew.EditWanted(str);
	    		
	    	  break;
	    	  
	      }
	      case ("EditPlace"): 
	      {
	        	  MessageEditPlace epos = new MessageEditPlace(client);  
	        	  epos.EditPlace(str);
	    		
	    	  break;
	    	  
	      }
	 

	      case ("GetBook"): 
	      {
	    	  GetBook gb=new GetBook(client);
	    	 client.sendToClient(gb.getbook(str));
 	    	 
	    	  break;
	    	  
	      }

	      
	      case ("LendBook"): 
	      {
	    	  MessageLendBook lendbook=new MessageLendBook();
	    	  client.sendToClient(lendbook.checklend(str));
	    	  break;
	    	  
	      }
	      case ("IsCopy"): 
	      {
	  		MessagesGetCopy mgc = new MessagesGetCopy(client);
			
				mgc.GetCopy();
			
			
	    	  break;
	    	  
	      }
	      case ("ExtendLending"): 
	      {
	    	 MessageExtendLending el=new MessageExtendLending();
	    	 client.sendToClient(el.extendlend(str));
	    	  break;
	    	  
	      }
	      case ("ReturnBook"): 
	      {
	    	  MessageReturnBook returnb= new MessageReturnBook(client);
	    	  returnb.returnabook(str);
	    	  break;
	    	  
	      }
	      case ("Search"): 
	      {
	    	  
	    	  System.out.println("$$$$$$$$$$$$$$$$$"+str[1]+str[2]);        
	    	  MessageSearch sb=new MessageSearch(client);
	    	  sb.SearchResult(str[1],str[2]);
	    	  
	    	  break;
	    	  
	      }
	      
	      case ("Workers2"): 
	      {
	    	 
	    	  MessageGetWorkers gw=new MessageGetWorkers(client);
	    	  gw.getWorkers();
	    	  break;
	    	  
	      }
	      case ("searchlending"): 
	      {
	    	  
	    	  System.out.println("search lending");
	    	  MessagesearchLending sr=new MessagesearchLending(client);
	    	  sr.SearchResult(str);
	    	  break;
	    	  
	      }
	      case ("MenualExtend"): 
	      {
	    	  
	    	  System.out.println("Menual Extend");
	    	  MenualExtendLending me=new MenualExtendLending(client);
	    	   me.extend(str);
	    	  break;
	    	  
	      }
	      case ("SearchFreeze"): 
	      {
	    	 
	    	  MessageFreeze mf=new MessageFreeze(client);
	    	  mf.MessageFreeze(str[1]);
	    	  break;
	    	  
	      }
	      case ("finalfreez"): 
	      {
	    	 
	    	  MessageFinalFreeze mf=new MessageFinalFreeze(client);
	    	  mf.FinalFreeze(str);
	    	  break;
	    	  
	      }
	    
	      case ("ActivityReport"): 
	      {
	    	// ArrayList<Object> result= new ArrayList<Object>();
	    	// result.add("Activity");
	        //MessageActivityReport ar=new MessageActivityReport(client);
	    	//  client.sendToClient(ar.ActivityReport());
	    	//  client.sendToClient(result);
	    	  MeassageActivitiyinit ai =new MeassageActivitiyinit(client);
	    	  ai.ActivityReportinit();
	    	  
	    	  break;
	    	  
	      }
	      case ("selectedDates"): 
	      {
	    	
	    	  MessageGenerateActivity ga =new MessageGenerateActivity(client);
	    	  ga.Generate(str);
	    	  
	    	  break;
	    	  
	      }
	      case ("GetLendReport"): 
	      {
	    	
	    	  MessageGetLendReport lend =new MessageGetLendReport(client);
	    	  lend.getreport(str);
	    	  
	    	  break;
	    	  
	      }
	      case ("OrderBook"):
	      {
	    	  System.out.println("$$$$$$$$$$$$$$$$$"+str[1]+str[2]);
	    	  MessageOrderBook ob= new  MessageOrderBook();
	    	  client.sendToClient(ob.MakeOrder(str[1],str[2]));
	    	  //AddUser.AddUser();
	    	  break;
	      }
	      case ("generatreportbydate"): 
	      {
	    	
	    	  MessageGetByDate r =new MessageGetByDate(client);
	    	  r.Generate(str);
	    	  
	    	  break;
	    	  
	      }
	      
	      default:
			  JOptionPane.showMessageDialog(null, "This Option isn't handeled yet!!!!",null, JOptionPane.WARNING_MESSAGE);
	    	  break;
	      }
	
  
    	  
	  }
	
}

